package lg.minecraft.plugin.cobblemoncore.config.mapping;

import com.cobblemon.mod.common.api.pokeball.PokeBalls;
import com.cobblemon.mod.common.pokeball.PokeBall;
import lg.minecraft.plugin.cobblemoncore.LGCobblemonCore;
import lg.minecraft.plugin.cobblemoncore.util.LocalizedName;
import lombok.Getter;
import net.minecraft.class_2960;

/**
 * @author langle__
 * @version 1.0
 */
@Getter
public class PokeBallMapping extends AbstractMapping<PokeBall> {

    public PokeBallMapping() {
        super(LGCobblemonCore.getInstance(), "pokeball.yml", LGCobblemonCore.getMappingDirectory().getPath());
    }

    @Override
    protected boolean isUseLocalFile() {
        return LGCobblemonCore.getMainConfig().isPokeBall();
    }

    @Override
    protected void loadFromDynamicSource() {
        for (PokeBall pokeBall : PokeBalls.INSTANCE.all()) {
            String displayName = LocalizedName.getPokeBallName(pokeBall);
            set(LGCobblemonCore.simplify(pokeBall.getName()), displayName);
            mapping.put(displayName, pokeBall);
            reverse.put(pokeBall, displayName);
        }
    }

    @Override
    protected void loadFromLocalFile() {
        for (String key : getKeys(false)) {
            String value = getString(key);
            class_2960 resource = LGCobblemonCore.createCobblemonResource(key);
            PokeBall pokeBall = PokeBalls.INSTANCE.getPokeBall(resource);
            if (pokeBall == null) {
                getPlugin().getLogger().warning("pokeball: " + key + " not found!");
                continue;
            }
            mapping.put(value, pokeBall);
            reverse.put(pokeBall, value);
        }
    }

}
